package com.taocore.top.title.action;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.taobao.api.ApiException;
import com.taobao.api.domain.Item;
import com.taobao.api.response.ItemsGetResponse;
import com.taocore.top.title.service.TaobaoService;

@Results({
	  @Result(name="success", location="sample-items.jsp")
})
public class SampleItemsAction extends ActionBase{

	static Logger _log = Logger.getLogger(SampleItemsAction.class.getName());
	
	private long cid;
	private List<Item> items;
	
	public String execute()
	{
		TaobaoService service = new TaobaoService();
		String fields = "num_iid,pic_url,title,volume";
		try {
			ItemsGetResponse rsp = service.search(cid, fields);
			if (rsp.isSuccess())
			{
				setItems(rsp.getItems());
			}
			else
			{
				_log.warning(TaobaoService.getError(rsp));
			}
		} catch (ApiException e) {
			_log.log(Level.SEVERE, "", e);
		}
		return SUCCESS;
	}

	public void setCid(long cid) {
		this.cid = cid;
	}

	public long getCid() {
		return cid;
	}

	public void setItems(List<Item> items) {
		this.items = items;
	}

	public List<Item> getItems() {
		return items;
	}
}
